﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebService.IServices;
using WebService.Model;

namespace HX_WebService_Core.Controllers
{
    [Route("api/Role")]
    [ApiController]
    public class RolesController : ControllerBase
    {
        readonly IRoleServices roleService;
        public RolesController(IRoleServices role)
        {
            roleService = role;
        }


        [HttpPost("FindAll")]
        public IActionResult FindAll()
        {
            IActionResult response = Unauthorized();
            var roles = roleService.Query().Result;
            var message = new MessageModel<Sys_Role>();
            if (roles != null && roles.Count > 0)
            {
                //var tokenString = BuildToken(user.First());
                message.Msg = null;
                message.Code = 200;
                message.Data = roles;
                response = Ok(new { Message = message });
            }
            else
            {
                message.Msg = "未查询到该账户，或者该账户已经删除";
                message.Code = 1;
                response = Ok(new { Message = message });
            }
            return response;
        }
    }
}
